import { DatePicker } from 'ant-design-vue';
import dayjs from 'dayjs'

/**
 * @description 处理首字母大学 abc => Abc
 * @param string
 * **/
export const changeStr = (str: string): string => {
  return str.charAt(0).toUpperCase() + str.slice(1)
}

/**
 * @description 随机生成颜色
 * @param {string} type
 * @return {string}
 * **/
export const randomColor = (type: 'rgb' | 'hex' | 'hsl'): string => {
  switch(type){
    case 'rgb':
      return window.crypto.getRandomValues(new Uint8Array(3)).toString()
    case 'hex':
      return (
        `#${Math.floor(Math.random() * 0xffffff).toString(16).padStart(6, `${Math.random() * 10}`)}`
      )
    case 'hsl':
      // 在25-95%范围内具有饱和度，在85-95%范围内具有亮度
      return [360 * Math.random(), 100 * Math.random() + '%', 100 * Math.random() + '%'].toString()
    default: 
        return ''
  }
}

/**
 * @description 复制文本
 * @param text
 * **/
export const copyText = (text: string) => {
  return new Promise((resolve) => {
    const copyInput = document.createElement('input')
    copyInput.value = text
    document.body.appendChild(copyInput)
    copyInput.select()
    document.execCommand('copy')
    copyInput.remove()
    resolve(true)
  })
}

/**
 * @description 判断字符串是否是base64
 * @param {string} 
 * **/
export const isBase64 = (str: string): boolean => {
  if(str === '' || str.trim() === '') {
    return false
  }
  try {
    return btoa(atob(str)) == str
  }catch(err){
    return false
  }
}

/**
 * @description 是否是生产环境
 * **/

// export const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)
// export const IS_DEV = ['decelopment'].includes(process.env.NODE_ENV)